package cloud.health.common.file.infrastructure;

import lombok.extern.slf4j.Slf4j;

import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;

@Slf4j
public class RuntimeUtil {

    public static void printGC() {
        for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
            long count = gc.getCollectionCount();
            long time = gc.getCollectionTime();
            String name = gc.getName();
            log.info("{}: {} times {} ms", name, count, time);
        }
    }

    public static long freeMemory() {
        return Runtime.getRuntime().freeMemory();
    }

}
